import { Button, View } from '@tarojs/components'
import Taro, { useDidShow } from '@tarojs/taro'
import { Component, useState,useEffect } from 'react'


//
const Enroll = (props) => {
  // const openId = Taro.getStorageSync("openid")

  // 定义一个变量来保存用户所注册的信息，（真实姓名，身份证，电话号，资格证明）
  // const [dietitian, setDietitian] = useState([{ enroll_name: "杨庆", enroll_idCard: "153465465465", enroll_phone: "351435434", qualification: "", openid: openId }])
  const [newData,setNewData]=useState(undefined)
  useEffect(()=>{
    setNewData(props.props) 
  },[])
  console.log("newData:",newData===undefined? undefined:newData.current[0])
  const handleUpdata = (data) => {
    console.log("props:",props.props)
    console.log("qualification:",props.props.current[0])
    console.log("data:",data)
    if(data==undefined){
      return
    }
    Taro.showModal({
      title: '温馨提示',
      content: '您是否要进行营养师的注册',
      success (res) {
        // 如果用户点击了确定按钮
        if (res.confirm) {
          // 向营养师表插入数据
          Taro.cloud.callFunction({
            name: 'enroll',
            data: {
              $url: 'Dietitian',
              dietitian: props.props,
            }
          }).then((res) => {
            // 操作提示
            Taro.showModal({
              title: '温馨提示',
              content: '您已成功提交',
              showCancel: false
            });
            return;
          })
        } else if (res.cancel) {
          // 如果用户点击了取消按钮
          console.log(3);
          Taro.showToast({
            title: '您取消了注册',
            icon: 'error',
            duration: 2000
          });
          return;
        }
      }
    })

  }
  return (
    <View className="box2">
      <Button className="box21" formType='submit' onClick={newData===undefined ? undefined:handleUpdata(newData.current[0])}>提交</Button>
      <Button className="box22" formType='reset' >重置</Button>
    </View>
  )


}
export default Enroll
